﻿function Convert-XmlFileWithXslt
{
    Param( 
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [ValidateScript({Test-Path $_ -PathType Leaf})] 
        [String]
        $Path,

        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [ValidateScript({Test-Path $_ -PathType Leaf})] 
        [String]
        $XslFile,

        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [ValidateScript({Test-Path (Split-Path $_) -PathType Container})] 
        [String]
        $outputFilePath
        )
    Process
    {
        $script:xslt = new-object system.xml.xsl.xslcompiledtransform -ErrorAction SilentlyContinue
        trap [System.Management.Automation.PSArgumentException] 
        {  # no 3.5, use the slower 2.0 one
           $script:xslt = new-object system.xml.xsl.xsltransform
        }
    
        ## load xslt file
        $xslt.load( $XslFile )
      
        ## transform 
        $xslt.Transform( $Path, $outputFilePath )

    }    


}